package com.simtop.beefsheepmaching.service.impl;

import com.simtop.beefsheepmaching.common.ServerResponse;
import com.simtop.beefsheepmaching.dao.ExperimentMapper;
import com.simtop.beefsheepmaching.pojo.experiment.Experiment;
import com.simtop.beefsheepmaching.pojo.experiment.ExperimentReportVo;
import com.simtop.beefsheepmaching.service.ExperimentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lvyongwei
 */
@Service
public class ExperimentServiceImpl implements ExperimentService {

    @Autowired
    private ExperimentMapper experimentMapper;

    /**
     * 添加实验报告
     * @param experiment
     * @return
     */
    @Override
    public boolean insertExperiment(Experiment experiment) {
        return experimentMapper.insertExperiment(experiment);
    }

    /**
     * 修改实验报告
     * @param experiment
     * @return
     */
    @Override
    public boolean updateExperiment(Experiment experiment) {
        return experimentMapper.updateExperiment(experiment);
    }

    /**
     * 获取实验报告列表
     * @param userId
     * @param message 关键字
     * @return
     */
    @Override
    public List<ExperimentReportVo> getAllReport(Integer userId, String message) {
        return experimentMapper.getAllReport(userId,message);
    }


    /**
     * 删除实验报告
     * @param id
     * @return
     */
    @Override
    public ServerResponse<String> deleteByExperimentId(Integer id) {
        if(id==null){
            return ServerResponse.createByErrorMsg("参数错误");
        }
        int effectNum = experimentMapper.deleteByExperimentId(id);
        if(effectNum != 1){
            return ServerResponse.createByErrorMsg("删除失败");
        }
        return ServerResponse.createBySuccess("删除成功");
    }
}
